home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / prog / bcc101.zip / PBCODE.ZIP / NET001.BAS
BASIC Source File  |  1993-03-19  |  12KB  |  319 lines

  1. ' This FILE: "NET001.BAS" is placed in the public domain by the author:
  2. ' Lewis    Balentine, 19 March 1993. The author specificly denies all warranties,
  3. ' exspressed or implied, of fittness or function.
  4. ' ->>>> use or abuse as you see fit <<<<-
  5. '----------------------------------------------------------------------------
  6. ' The code in this file is intended to be compiled with Spectra Publishing's
  7. ' Power Basic version 3.0. It provides functions that interface the Novell
  8. ' Netware connection API. Sample program code prints this information to
  9. ' the screen. (FYI: TABS set to 4)
  10. '
  11. ' Functions included are:
  12. '     GetConnectNummber%     ->                Netware Logical Connection number
  13. '    GetConnectInfo%        ->                Information logged in user
  14. '    GetNode$            ->                Stations physical node
  15. '
  16. '----------------------------------------------------------------------------
  17. 'PGN PAGE: XXX in this program remarks refers to a page in the book:
  18. '    "Programers Guide to Netware", Charles G. Rose, (c) 1990 McGraw Hill.
  19. '============================================================================
  20. $compile exe
  21. $debug map on
  22. $dim array
  23. DECLARE FUNCTION GetStrLoc&(byval AllocHandle%)        ' so ASM CALL can find it
  24. '----------------------------------------------------------------------------
  25. ' Constants for use with PB3's REGS function/statement.
  26. %FLAGS = 0
  27. %AX    = 1
  28. %BX    = 2
  29. %CX    = 3
  30. %DX    = 4
  31. %SI    = 5
  32. %DI    = 6
  33. %BP    = 7
  34. %DS    = 8
  35. %ES    = 9
  36. '----------------------------------------------------------------------------
  37. type ConInfoReq                    ' Connection Information Request Buffer
  38.     length     as word                    ' (LoHi) Request buffer length (4 - 2 = 2)
  39.     cll        as byte                    ' Set to &H16
  40.     con        as byte                    ' logical connection number
  41. end type
  42.  
  43. type ConInfoRep                    ' Connection Information Reply Buffer
  44.     length     as word                    ' (LoHi) Reply buffer length (64 - 2 = 62)
  45.     id        as Dword                ' (HiLo) Object ID
  46.     tipe    as word                    ' (HiLo) Object Type
  47.     nam     as string * 48            ' Object Name
  48.     Yr        as Byte                    ' Log in Year where 0 = 1980
  49.     Mo        as Byte                    '        Month        (1 to 12)
  50.     Dy        as Byte                    '         Day        (1 to 31)
  51.     Hr        as Byte                    '         Hour         (0 to 23)
  52.     Mn        as Byte                    '         Minute        (0 to 59)
  53.     Sc        as Byte                    '         Second        (0 to 59)
  54.     Wk        as Byte                    '         WeekDay where 0=Sunday
  55.     Extra    as Byte                    ' Undefined extra byte
  56. end type
  57. '----------------------------------------------------------------------------
  58. ' the FourByte, TwoByte types and HiLoWord, HiLoDWord are used in the functions
  59. ' SwapBytesW and SwapBytesDW.
  60. Type FourByte
  61.     B1 as Byte
  62.     B2 as Byte
  63.     B3 as Byte
  64.     B4 as Byte
  65. end Type
  66. Type TwoByte
  67.     B1 as Byte
  68.     B2 as Byte
  69. end Type
  70. Union HiLoWord
  71.     Wrd as Word
  72.     BB  as TwoByte
  73. end Union
  74. Union HiLoDWord
  75.     DW as Dword
  76.     BB  as FourByte
  77. end Union
  78. '============================================================================
  79. ' This is the "MAIN" code of the prgram. It prints Netware Connection
  80. ' Information about the workstation and logged on user.
  81. '============================================================================
  82. start:
  83. dim info as ConInfoRep
  84.  
  85. connect%=GetConnectNumber%
  86.  
  87. print
  88.  
  89. if connect%=0 then
  90.     print "This workstation is not logged in to the network."
  91.     end
  92. end if
  93.  
  94. errr%=GetConnectInfo%(connect%,info)
  95.  
  96. if errr%<>0 then
  97.     print "Get Netware Connection Information failed."
  98.     end
  99. else
  100.     Print "Logical Connection number is (DEC): ";connect%
  101.     Print "                     LogIn Name is: "; trim$(info.nam)
  102.     print "        Netware Object ID is (HEX): "; DWHex$(SwapBytesDW???(info.id))
  103.     print "      Netware Object Type is (HEX): ";Right$(DWHex$(SwapBytesW??(info.tipe)),4)
  104.     print "         WorkStation Node is (HEX): "; getnode$
  105. end if
  106. end
  107. '=============================================================================
  108. ' Below are the function used by the program.
  109. '=============================================================================
  110. ' function to return Netware Logical Connection number
  111. function GetConnectNumber%                    ' PGN PAGE: 274
  112. ' if 0 then not logged in
  113.     local     c%
  114.     !xor     AX,AX                             ' zero AX
  115.     !mov     AH,&Hdc                            ' Netware API call for Connect #
  116.     !int     &H21                              ' Call Netware (returns AX=&Hdc32)
  117.     !xor     AH,AH                             ' Mask off the high byte
  118.     !mov     c%,AX                             ' AL contains connection number
  119.     GetConnectNumber%= c%
  120. end function
  121. '----------------------------------------------------------------------------
  122. ' function to return info about the Netware object at a specific connection #
  123. ' PGN PAGE: 272
  124. function GetConnectInfo% (con%, reply as coninforep) Local
  125.     dim request as ConInfoReq
  126.     request.length=2
  127.     request.cll=&H16
  128.     request.con=con%
  129.     reply.length=62
  130.     reg %ES, varseg(reply)
  131.     reg %DI, varptr(reply)
  132.     reg %DS, varseg(request)
  133.     reg %SI, varptr(request)
  134.     reg %AX, &HE300
  135.     call interrupt &H21
  136.     reply.Extra = Reg(%AX) and &H00FF    ' 0 indicates succesful call
  137.     GetConnectInfo%=reply.extra
  138. end function
  139. '----------------------------------------------------------------------------
  140. ' funtion to return 6 byte Physical Node Address of the requesting workstation
  141. ' PowerBasic does not have a 6 byte integer type so we are going to return
  142. ' a 12 byte string representation of the unsigned Hexidecimal number.
  143. ' There is probably a better way to do this, but ....
  144. function GetNode$                         ' PGN PAGE: 276
  145.     temp$="000000000000"                ' 6 bytes requires 12 characters
  146.     ! push      DI                      ; save Destination Index
  147.     !
  148.     ! mov         AX,&Hee00
  149.     ! int        &H21                    ; Call Netware
  150.     !
  151. '    ! mov       AX,&h4321                ;   for test of conversion
  152. '    ! mov       BX,&h8765                ;   for test of conversion
  153. '    ! mov          CX,&hCBA9                ;   for test of conversion
  154.     !
  155.     ! push        CX                        ; Node returned in CX,BX,AX
  156.     ! push      BX
  157.     ! push        AX
  158.  
  159.     ' setup our working string
  160.     ! mov     AX,temp$                    ' string handle
  161.     ! push  AX                            ' now for location and length
  162.     ! call  getstrloc                    ' return: location=DX:AX, length=CX
  163.     ! dec    CX                            ' reduce count by one
  164.     ! add   AX, CX                        ' we need the end of the string
  165.     ! mov   ES, DX                        ' store our address    of string
  166.     ! mov   DI, AX                        '   in ES:DI
  167.  
  168.  
  169.     ! std                               ; set direction flag for decriment
  170.     ! mov        CX,&h0003
  171.     GetNodeLoop:
  172.     ! pop       BX                        ; get word from stack
  173.     ! mov        AH,4                    ; (4 nibbles)
  174.     ! call      WHex                    ; translate
  175.     ! loop        GetNodeLoop
  176.  
  177.     ! pop       DI                        ; restore resisters
  178.     ! cld
  179.     GetNode$=temp$
  180. end function
  181. '----------------------------------------------------------------------------
  182. ' functions to swap High and Low bytes of a Word/DWord
  183. ' Netware was origionally only available on a Motorola 6800 server. Motorola
  184. ' stores numbers with the most significant byte first. Intel stores numbers
  185. ' with the least significant byte first. This function is use to translate
  186. ' the old style unsigned wird values. Note that it does not change the input.
  187. function SwapBytesW?? (wrd??) Local
  188.     dim temp as HiLoWord
  189.     temp.Wrd=wrd??
  190.     swap temp.bb.b1 , temp.bb.b2
  191.     SwapBytesW??=temp.Wrd
  192. end function
  193. '----------------------------------------------------------------------------
  194. function SwapBytesDW??? (DW???) Local
  195.     dim temp as HiLoDWord
  196.     temp.DW=DW???
  197.     'print hex$(temp.bb.b1), hex$(temp.bb.b4)
  198.     swap temp.bb.b1, temp.bb.b4
  199.     swap temp.bb.b2, temp.bb.b3
  200.     SwapBytesDW???=temp.DW
  201. end function
  202. '----------------------------------------------------------------------------
  203. ' function to return the value of the string representation of Hexidecimal
  204. ' number. PB's "&Hxxxx" is limited to compile time and/or two bytes.
  205. ' NOTE: This function assumes unsigned strings !
  206. ' NOTE: This function ignores the invalid characters!
  207. function DWHexVal???( DW as string) Local
  208.     dim temp as string
  209.     temp=ucase$(DW)
  210.     while len(temp)>0
  211.         p= instr("0123456789ABCDEF",left$(temp$,1))
  212.         if p>0 then
  213.             shift left t???,4
  214.             t???=t???+(p-1)
  215.         end if
  216.         ' print p,t???,temp
  217.         temp=mid$(temp,2)
  218.     wend
  219.     DWHexVal???=t???
  220. end function
  221. '----------------------------------------------------------------------------
  222. ' function to return a 8 character Hexidecimal string representation of
  223. ' a four byte DoubleWord variable. (PB's HEX$ function is limited to 2 Bytes)
  224. function DWHex$ (DW as DWord) Local
  225.     temp$="87654321"                    ' allocate 8 byte character string
  226.  
  227.     ' PAGE: 333 of PB3 Programers Guide
  228.     ' " ... save the SI,DI,BP,DS,SS and SP registers."
  229.     ' of these we only modify the DI register.
  230.     ! push      DI                      ; save Destination Index
  231.  
  232.     ' setup our working string
  233.     ! mov     AX,temp$                    ' string handle
  234.     ! push  AX                            ' now for location and length
  235.     ! call  getstrloc                    ' return: location=DX:AX, length=CX
  236.     ! dec    CX                            ' reduce count by one
  237.     ! add   AX, CX                        ' we need the end of the string
  238.  
  239.     ' setup our DoubleWord Variable
  240.     ! les    di,[bp+6]                    ' get the address from the stack
  241.     ! mov    BX, es:[di]                    ' store lo word
  242.     ! inc    di                            ' move index foward
  243.     ! inc   di                            ' two bytes
  244.     ! mov    CX, es:[di]                    ' store hi word
  245.     ! mov   ES, DX                        ' store our address    in of string
  246.     ! mov   DI, AX                        '   in ES:DI
  247.     ! std                                ' set the direction flag
  248.     ! mov    AH,4                        ' 1 word = 4 nibbles
  249.     ! call  Whex                        ' now convert
  250.     ! mov    BX,CX                        ' get the hi word
  251.     ! mov    AH,4                        ' 1 word = 4 nibbles
  252.     ! call  WHex                        ' convert it
  253.     ! pop      DI                            ' restore Destination Index
  254.     ' PAGE: 333 of PB3 Programers Guide
  255.     ' " ... all these calls also require you clear ... the processor
  256.     ' direction flag before returning to caller. ..."
  257.     ! cld
  258.     DWHex$=temp$
  259. end function
  260. '----------------------------------------------------------------------------
  261. ' This function trims the "white space" from both ends of string.
  262. ' It also removes ANY contol characters (0 to 31).
  263. function trim$(t$)
  264.     dim temp as string
  265.     for i=1 to len(t$)
  266.         tt$=mid$(t$,i,1)
  267.         if tt$=>" " then temp=temp+tt$
  268.     next i
  269.     trim$=ltrim$(rtrim$(temp))
  270. end function
  271. '=============================================================================
  272. ' below are misc ASSEMBLY soubroutines called from the inline ASM functions
  273. '=============================================================================
  274. ' Most, if not all, of this assembly work could have been done in pure Basic.
  275. ' The main reason I did it in assembly was to get some idea of what could 
  276. ' be done (and how) with the INLINE ASM capability of PB3. 
  277. ' Having gone to the trouble ..... I am going to use it.
  278. '-----------------------------------------------------------------------------
  279.     ! ; ASM routine converts the WORD in BX to a Hex String representation
  280.     ! ; on entry    
  281.     ! ;        ES:DI = pointer to end of string (works right to left)
  282.     ! ;        BX    = value to be converted
  283.     ! ;     AH    = number of nibbles (hex digits) to convert (0 to 4)
  284.     ! ; direction flag = set (decrement)
  285.     ! ; on exit   
  286.     ! ;        BX    = undefined (contents rotated, 4 digits->BXin=BXout)
  287.     ! ;        AH      = zero
  288.     ! ;        AL      = last Hex Character
  289.     ! ;        AX    = undefined (AH =0, AL last Hex digit)
  290.     ! ;        ES:DI = byte in front of hex string
  291.     ! ; The only other register affected is the flag register.
  292.     ! ; NOTES:
  293.     ! ;   NO ERROR CHECKING, THIS WILL WRITE OVER ANYTHING (or at least try)!!
  294.     ! ;   THIS ROUTINE USES A NEAR RETURN, MUST CALL FROM SAME CODE SEG !!!!
  295.     WHex:
  296.     ! cmp        AH,0                    ; if 0 then
  297.     ! jz        WHexExit                ;     out of here
  298.     ! mov       AL, BL                     ; get value from BX
  299.     ! and       AL, &h0F                ; mask off low nibble
  300.     ! dec        AH                        ; sub one from our counter
  301.     ! ror        BX, 1                    ; rotate the next nibble in BX
  302.     ! ror        BX, 1                    ;     four rotates are used so that
  303.     ! ror        BX, 1                    ;   this will work on an 8088
  304.     ! ror        BX, 1                    ;   rotate is used to preserve BX
  305.     ! cmp       AL, &H0009                ; if greater than 9 then
  306.     ! jg        WHexAlpha                 ;   jump to alpha character
  307.     ! add       AL, &h30                  ; else add offset for numeric
  308.     ! stosb                                ; store val in AL at ES:DI, DI=DI-1
  309.     ! jmp        WHex                    ; do it again Sam ...
  310.     WHexAlpha:
  311.     ! add        AL, &h37                ; add offset for alpha character
  312.     ! stosb                                ; store val in AL at ES:DI, DI=DI-1
  313.     ! jmp        WHex                    ; do it again Sam ...
  314.     WHexExit:
  315.     ! retn                                ; back to whince we came (I hope)
  316. '-----------------------------------------------------------------------------
  317. '   more to come, maybe ....
  318. ' End of File <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  319.